<?php
/**
 * 基础库(对象通用处理函数)
 */

namespace Deyi\Functions;


class ObjectFunction
{

    public static function toAo($result)
    {
        if (!is_object($result)) {
            return null;
        }

        return (object)array_filter($result->dump(), function ($key) {
            if (strpos($key, '_') === 0) {
                return false;
            }
            return true;
        }, ARRAY_FILTER_USE_KEY);
    }

    public static function toArray($result)
    {
        if (!is_object($result)) {
            return [];
        }

        return array_filter($result->dump(), function ($key) {
            if (strpos($key, '_') === 0) {
                return false;
            }
            return true;
        }, ARRAY_FILTER_USE_KEY);
    }

}
